/*
 * MIT License
 *
 * Copyright (c) 2020 wen.gu <454727014@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/***************************************************************************
 * Name: dog_plugin.h
 *
 * Purpose: plugin interface define for puppy dog
 *
 * Developer:
 *   wen.gu , 2020-08-19
 *
 * TODO:
 *
 ***************************************************************************/

/******************************************************************************
 **    INCLUDES
 ******************************************************************************/
#ifndef __DOG_PLUGIN_H__
#define __DOG_PLUGIN_H__
#include <string>

#include "dog_types.h"
#include "dog_errors.h"
/******************************************************************************
 **    MACROS
 ******************************************************************************/
 /** plugin header version
  * note: plugin manager will check this version to jduagement current
  *       plugin is compatible or not?
  */
#define PLUGIN_HEADER_VER "00.01.00"

  /** the name of plugin entry, used by plugin manager */
#define PLUGIN_ENTRY_NAME "_PluginEntry"
#define PLUGIN_VER_FUNC_NAME "baseOnPluginHeaderVersion"

/** the entry of plugin, used by plugin implementation
 ** note: this macro can't use in namespace xxx, this is c style function **
 */
#define PLUGIN_ENTRY(pluginClass, name, version, author) \
    dog::Plugin* _PluginEntry(){ \
        dog::Plugin mp = new pluginClass(name, version, author); \
        return mp; \
    } \
    const char* baseOnPluginHeaderVersion(){ \
        return PLUGIN_HEADER_VER; \
    }

/******************************************************************************
 **    TYPE DEFINITIONS
 ******************************************************************************/
namespace dog
{

/******************************************************************************
 **    CLASSES/FUNCTIONS DEFINITIONS
 ******************************************************************************/
struct ComponentCreateParam;
class Component;

class DOG_CLASS Plugin
{
public:
    Plugin(ConstString& name, ConstString& version, ConstString& author)
        :mName(name),
        mVersion(version),
        mAuthor(author)
    {
        /** todo somethings */
    }

    virtual ~Plugin() { /** todo something */ }
public:
    virtual ConstString& name() const { return mName; }
    virtual ConstString& version() const { return mVersion; }
    virtual ConstString& author() const { return mAuthor; }

    /** create a component instance(real plugin must implement this API)
     *@parameter

     * [in] param the parameter to request the component
     * [io] comp  the pointer point to component instance,if failed, then nullptr
     *
     *@return
     *   success: PandaErrc::OK, failed: error code.
     */
    virtual DogErrc createComponent(const ComponentCreateParam* param, Component** comp) = 0;
protected:
    std::string mName = "";
    std::string mVersion = "";
    std::string mAuthor = "";
};

} /** namespace dog */

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/** the type of plugin entry function, used by plugin manager */
typedef dog::Plugin* (*pluginEntryFunc_t)();
typedef const char* (*pluginHdrVerFunc_t)();

/** the plugin entry define */
DOG_API_C dog::Plugin* _PluginBaseEntry();

/** return the version of media plugin header */
DOG_API_C const char* baseOnPluginHeaderVersion();

#endif /** !__DOG_PLUGIN_H__ */

